<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${rootPath}.dao.${entityName}Dao">

    <sql id="fields">
    <#list fieldList as var>
        <#if var_has_next>
            <#if var[1] == 'Date'>
                DATE_FORMAT( ${var[0]},'%Y-%m-%d %H:%i:%s')  ${var[0]},
            <#else>
            ${var[0]},
            </#if>
        <#else>
            <#if var[1] == 'Date'>
                DATE_FORMAT( ${var[0]},'%Y-%m-%d %H:%i:%s')  ${var[0]}
            <#else>
            ${var[0]}
            </#if>
        </#if>
    </#list>
    </sql>
    <!-- 分页查询列表-->
    <select id="list" resultType="${rootPath}.model.${entityName}" parameterType="${rootPath}.model.${entityName}">
        select
        <include refid="fields"/>
        from ${tableName}
    </select>
    <!--查询单条 -->
    <select id="getById" resultType="${rootPath}.model.${entityName}">
        select
        <include refid="fields"/>
        from ${tableName} where id = ${r"#{value}"}
    </select>

    <update id="update" parameterType="${rootPath}.model.${entityName}">
        UPDATE  ${tableName}
        <set>
        <#list fieldList as var>
            <if test="${var[0]} != null and ${var[0]} != '' ">
            ${var[0]} = ${r"#{"}${var[0]}${r"}"},
            </if>
        </#list>
        </set>
        where id = ${r"#{id}"}
    </update>

    <insert id="insert" parameterType="${rootPath}.model.${entityName}">
        insert into ${tableName}
    <#list fieldList as var>
        <#if var_has_next>
        ${var[0]},
        <#else>
        ${var[0]}
        </#if>
    </#list>
        values(
    <#list fieldList as var>
        <#if var_has_next>
        ${r"#{"}${var[0]}${r"}"},
        <#else>
        ${r"#{"}${var[0]}${r"}"}
        </#if>
    </#list>
        )
    </insert>

    <delete id="deletebth">
        delete from ${tableName} where id IN
        <foreach collection="array" item="item" open="(" close=")" separator=",">
        ${r"#{item}"}
        </foreach>
    </delete>

</mapper>